<template>
	<view>
		<!-- <import src="../../../wxParse/wxParse.wxml"></import> -->
		<view class="container b-f p-b">
			<view class="article-title">
				<text class="f-32">{{ detail.article_title }}</text>
			</view>
			<view class="article-little dis-flex flex-x-between m-top10">
				<view class="article-little__left">
					<text class="article-views f-24 col-8">{{ detail.show_views }}次浏览</text>
				</view>
				<view class="article-little__right">
					<text class="article-views f-24 col-8">{{ detail.view_time }}</text>
				</view>
			</view>
			<view class="article-content m-top20">
				<!-- <template is="wxParse" data="{{wxParseData:content.nodes}}"></template> -->
				<rich-text :nodes="article"></rich-text>
			</view>
		</view>

		<!-- 快捷导航 -->
		<shortcut></shortcut>
	</view>
</template>

<script>
	import shortcut from '../../../components/goods/shortcut.vue'
	export default {
		components: {
			// （组件命名）
			shortcut
		},
		props: {
			shortcut: {}
		},
		data() {
			return {
				article: '',
				strings: '',
				// 文章详情
				detail: {},
			}
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			// 获取文章详情
			this.getArticleDetail(options.article_id);
		},

		methods: {
			/**
			 * 获取文章详情
			 */
			getArticleDetail(article_id) {
				let _this = this;
				_this._get('article/detail', {
					article_id
				}, function(result) {
					let detail = result.data.detail;
					// 富文本转码
					if (detail.article_content.length > 0) {
						// console.log(detail.article_content);
						let cont = _this.htmlDecodeByRegExp(detail.article_content);
						let article = cont.replace(/<img/g, "<img style='max-width:100%;height:auto;'");
						_this.setData({
							'article': article
						});
					}
					_this.setData({
						detail
					});
				});
			},

			/*2.用正则表达式实现html解码*/
			htmlDecodeByRegExp: function(str) {
				var s = "";
				if (str.length == 0) return "";
				s = str.replace(/&amp;/g, "&");
				s = s.replace(/&lt;/g, "<");
				s = s.replace(/&gt;/g, ">");
				s = s.replace(/&nbsp;/g, " ");
				s = s.replace(/&#39;/g, "\'");
				s = s.replace(/&quot;/g, "\"");
				return s;
			},

			/**
			 * 分享当前页面
			 */
			onShareAppMessage() {
				// 构建页面参数
				let params = _this.urlEncode({
					'article_id': this.data.detail.article_id,
					'referee_id': _this.getUserId()
				});
				return {
					title: this.data.detail.article_title,
					path: "/pages/article/detail/index?" + params
				};
			},
		}
	}
</script>

<style>
	/* wxParse.wxss */

	page {
		background: #fff;
	}

	.container {
		padding: 30upx;
	}
	.article-content {
	  font-size: 28rpx;
	}


	.wxParse-img {
		width: 706upx;
	}
</style>
